<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">订单流水号：{{ $order->pay_sn }}</h3>
        <div class="box-tools">
            <div class="btn-group pull-right" style="margin-right: 10px">
                <a href="{{ route('order.index') }}" class="btn btn-sm btn-default"><i class="fa fa-list"></i> 列表</a>
            </div>
        </div>
    </div>
    <div class="box-body">
        <table class="table table-bordered">
            <tbody>
            <tr>
                <td>买家：</td>
                <td>{{ $order->address->consignee }}</td>
                <td>下单时间：</td>
                <td>{{ $order->paid_at }}</td>
                <td>备注</td>
                <td>{{$order->extra}}</td>
            </tr>
            <tr>
                <td>支付方式：</td>
                <td>{{isset(\App\OrderPay::$payTypeMap[$order->pay_type]) ? \App\OrderPay::$payTypeMap[$order->pay_type] : '零元支付' }}</td>
                <td>支付渠道单号：</td>
                <td>{{ $order->pay_sn }}</td>
            </tr>
            <tr>
                <td>收货地址</td>
                <td colspan="3">{{ $order->address->province }} {{ $order->address->city }} {{ $order->address->district }} {{ $order->address->address}}<span>电话:{{$order->address->mobile}}</span></td>
            </tr>
            <tr>
                <td rowspan="{{ $order->goods->count() + 1 }}">商品列表</td>
                <td>商品图片</td>
                <td>商品名称</td>
                <td>单价</td>
                <td>数量</td>
                <td>首购/复购</td>

            </tr>
            @foreach($order->goods as $item)
                <tr>
                    <td><img src="{{$item->good_object['goods_thumbnail']}}" width="100px" height="100px"></td>
                    <td>{{ $item->good_object['goods_name'] }} </td>
                    <td>￥{{ $item->good_price}}</td>
                    <td>{{ $item->good_object['buy_num'] }}</td>
                    <td>@if($order->is_recharge) 复购  @else 首购@endif</td>
                </tr>
            @endforeach
            @if(isset($order->coupons))
            <tr>
                <td>优惠券：</td>
                <td colspan="3">{{ $order->coupons->coupon_object['name'] }}</td>
                <td>优惠额度：</td>
                <td>{{ $order->coupons->coupon_object['money'] }}</td>
            </tr>
                @else
                <tr>
                    <td>优惠券：</td>
                    <td colspan="3">未使用优惠券</td>
                    <td>优惠额度：</td>
                    <td>0</td>
                </tr>

            @endif
            <tr>
                <td>订单金额：</td>
                <td colspan="3">￥{{ $order->total_money }}</td>
                <td>订单状态：</td>
                <td>{{ \App\OrderPay::$shipStatusMap[$order->ship_status] }}</td>
            </tr>
            <tr>
                <td>实付金额：</td>

                <td >￥{{ $order->pay_price+$order->pay_balance }}</td>
                <td>余额支付：</td>
                <td>￥{{$order->pay_balance}}</td>

                <td>退款状态：</td>
                <td>{{ \App\OrderPay::$refundStatusMap[$order->refund_status] }}</td>
            </tr>
            <!-- 如果订单未发货，展示发货表单 -->
            @if($order->ship_status === \App\OrderPay::SHIP_STATUS_PENDING&&$order->refund_status!=\App\OrderPay::REFUND_STATUS_APPLIED)
                <tr>
                    <td colspan="4">
                        <form action="{{ route('admin.orders.ship', [$order->order_pay_id]) }}" method="post" class="form-inline">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <div class="form-group {{ $errors->has('express_company') ? 'has-error' : '' }}">
                                <label for="express_company" class="control-label">物流公司</label>
                                <input type="text" id="express_company" name="express_company" value="" class="form-control" placeholder="输入物流公司">
                                @if($errors->has('express_company'))
                                    @foreach($errors->get('express_company') as $msg)
                                        <span class="help-block">{{ $msg }}</span>
                                    @endforeach
                                @endif
                            </div>
                            <div class="form-group {{ $errors->has('express_company') ? 'has-error' : '' }}">
                                <label for="express_no" class="control-label">物流单号</label>
                                <input type="text" id="express_no" name="express_no" value="" class="form-control" placeholder="输入物流单号">
                                @if($errors->has('express_no'))
                                    @foreach($errors->get('express_no') as $msg)
                                        <span class="help-block">{{ $msg }}</span>
                                    @endforeach
                                @endif
                            </div>
                            <button type="submit" class="btn btn-success" id="ship-btn">发货</button>
                        </form>
                    </td>
                </tr>
                @elseif($order->ship_status===\App\OrderPay::SHIP_STATUS_SURE_ORDER&&$order->refund_status!=\App\OrderPay::REFUND_STATUS_APPLIED)
                <tr>
                    <td colspan="4">
                        <form action="{{ route('order.sure', [$order->order_pay_id]) }}" method="post" class="form-inline">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">

                            <div class="form-group {{ $errors->has('express_company') ? 'has-error' : '' }}">
                                <label for="express_no" class="control-label">是否打印快递单号</label>

                                <div class="switch" data-on="primary" data-off="info">
                                    <input type="checkbox" checked name="print" />
                                </div>
                            </div>
                            <button type="submit" class="btn btn-success" id="ship-btn">确认订单</button>
                        </form>
                    </td>
                </tr>
            @else
                <!-- 否则展示物流公司和物流单号 -->
                <tr>
                    <td>物流公司：</td>
                    <td>{{ $order->express_company }}</td>
                    <td>物流单号：</td>
                    <td>{{ $order->mail_no ?? $order->express_no }}</td>
                    <td><a href="{{route('order.print',[$order->order_pay_id])}}" target="_blank" class="btn btn-success" >打印快递模板</a></td>

                </tr>

            @endif
            @if(!$order->closed)
            @if($order->ship_status==\App\OrderPay::SHIP_STATUS_SURE_ORDER||$order->ship_status==\App\OrderPay::SHIP_STATUS_PENDING)
                <tr>
                    <td>
                        <form action="{{ route('order.cancel', [$order->order_pay_id]) }}" method="post" class="form-inline">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn btn-success" id="ship-btn">取消订单</button>
                        </form>
                    </td>
                </tr>
                @endif
                @endif
            </tbody>
        </table>

    </div>
</div>